home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 029a / masview.zip / TTT1.C < prev    next >
Text File  |  1991-10-23  |  864b  |  45 lines

  1. /* ttt1.c - main module */
  2.  
  3. #include "stdio.h"
  4. #include "ttt.h"
  5.  
  6. char board[ 3 ][ 3 ];    /* playing board, global 2-dimension array */
  7.  
  8. main()        /* main program */
  9. {
  10.     int turn;
  11.     char s[ 80 ];
  12.  
  13.     printf( "Welcome to Tic-Tac-Toe... you will be 'X'\n\n" );
  14.     printf( "Do you want to go first? (Y/N) " );
  15.     gets( s );
  16.     if ( tolower( s[ 0 ] ) == 'y' )
  17.         turn = HUMAN;
  18.     else turn = COMPUTER;
  19.  
  20.     for ( set_up_board(); ! game_over( board ); print_board() )
  21.         switch( turn )
  22.         {
  23.             case COMPUTER:
  24.                 computer_move();
  25.                 turn = HUMAN;
  26.                 break;
  27.             case HUMAN:
  28.                 human_move();
  29.                 turn = COMPUTER;
  30.                 break;
  31.             default:
  32.                 break;
  33.         }
  34. }
  35.  
  36. static set_up_board()    /* set up the playing board to be empty and print it */
  37. {
  38.     int x, y;
  39.  
  40.     for ( x = 0; x < 3; ++x )
  41.         for ( y = 0; y < 3; ++y )
  42.             board[ x ][ y ] = EMPTY;
  43.     print_board();
  44. }
  45.